package org.huang.eureka.client;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

@RestController
public class DcController {


    @Autowired
    DiscoveryClient discoveryClient;

    @Value("${server.port}")
    private String port;


    @GetMapping("/hello")
    public String helloWorld() {
        String services = "["+port+"]hello Services: " + discoveryClient.getServices();
        System.out.println(services);
        return services;
    }


    @GetMapping("/user/{username}/{age}")
    public User getUser1(@PathVariable String username,@PathVariable Integer age){
        return new User(username,age);
    }

    @GetMapping("/user")
    public User getUser2( String username,Integer age){
        return new User(username,age);
    }


    @PostMapping("/postUser")
    public User getUser3(@RequestBody User user){
        System.out.println("user:"+user);
        return user;
    }

    @GetMapping("/getUser")
    public User getUser4(@RequestBody User user){
        System.out.println("user:"+user);
        return user;
    }
}